# Table 2: Descriptive Statistics


# 1. Load Packages ----

library(stargazer)

# 2. Read in Data ----
# Data at the Voting Day Level
load(file = "df_voxit_individual_analysis.RData")

# Data at the Proposition Level
load(file = "df_voxit_individual_props.RData")

# 3. Prepare in Data ----
# Data at the Voting Day Level
# Select relevant variables
df_dstats <- as.data.frame(voxit_individual [voxit_individual $prop_voxit>1,
                                     c("turnout","utility_optc_sum",
                                       "utility_optc_max","prop_voxit",
                                       "initiative", "initiative_counter",
                                       "referendum_fak", "referendum_comp",
                                       "age", "male", "uni", "married",
                                       "knowledge", "leftright")])

# Data at the Proposition Level
df_dstats_c <- as.data.frame(voxit_propositions[voxit_propositions$turnout==1,
                                             c("empty_ballot",
                                               "utility_optc",
                                               "prop_nr_day")])

# 4. Create and Save Table ----
# Data at the Voting Day Level
stargazer(df_dstats, 
          covariate.labels = c("Turnout", "Utility sum", "Utility max",
                               "No. of propositions", "Initiative", 
                               "Counter initiative",
                               "Optional referendum", "Compulsory referendum",
                               "Age", "Male", "Uni", "Married", 
                               "Political knowledge",
                               "Political ideology"),
          summary.stat = c("n", "mean", "sd", "min", "max"),
          summary = T, float = F, digits = 2, out = "Table2A.tex")

# Data at the Proposition Level
stargazer(df_dstats_c,
          summary.stat = c("n", "mean", "sd", "min", "max"), digits = 2,
          out = "Table2B.tex")




